/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package co.edu.senaclem.persistencia;

import co.edu.senaclem.modelo.Guarda;
import co.edu.senaclem.modelo.Personal;
import com.lowagie.text.xml.simpleparser.EntitiesToSymbol;
import java.sql.ResultSet;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author anfeles
 */

@Stateless
public class GuardaDAO implements IGuardaDAO{
    @PersistenceContext
    private EntityManager entityManager;
    
    @Override
    public void eliminar(Guarda guarda) throws Exception {
        entityManager.remove(guarda);
    }

    @Override
    public void modificar(Guarda guarda) throws Exception {
        entityManager.merge(guarda);
    }

    @Override
    public void insertar(Guarda guarda) throws Exception {
        try {
            entityManager.persist(guarda);
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public Guarda consultarPorId(Long documento) throws Exception {
        try {
            return entityManager.find(Guarda.class, documento);
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public List<Guarda> consultar() throws Exception {
        try {
            String jpql="Select c From Guarda c";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        } catch (RuntimeException e) {
            throw e;
        }
    }

   
    
}
